package com.ima.web.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ima.web.beans.db.Roles;
import com.ima.web.dao.RolesDao;

@Repository
public class RolesDaoImpl implements RolesDao {

	private SessionFactory sessionFactory;
	
	@Autowired
	public void setDependencies(SessionFactory sessionFactory){
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public void save(Roles data) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(Roles data) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<Roles> list(Roles data) {
		Session s = sessionFactory.getCurrentSession();
		Criteria c = s.createCriteria(Roles.class);
		c.add(Example.create(data));
		
		List<Roles> r = c.list();

		return r;
	}

	@Override
	public Roles findById(int id) {
		Session s = sessionFactory.getCurrentSession();
		
		Roles r = (Roles)s.load(Roles.class, id); 

		s.update(r);
		
		
		return r;
	}

}
